import { TimeObserver } from "./TimeObserver";

export class TimeUpdateCount extends TimeObserver {
    protected index: number = 0
    protected temp: number = 0;
    //每次加载个数
    protected count: number = 0
    constructor(func: (time: number) => void, d: number, c: number = 1) {
        super(func, d)
        this.count = c;
    }
    clear() {
        this.index = 0;
        this.temp = 0;
    }
    check(dt: number) {
        this.temp += dt;
        if (this.temp >= this.duration) {
            this.temp -= this.duration
            if (this.func) {
                for (let index = 0; index < this.count; index++) {
                    this.func(this.index++);
                }
            }
        }
        return false;
    }
}